package com.sfy.login.controller;


import com.sfy.login.dto.request.LoginRequest;
import com.sfy.login.factory.LoginServiceFactory;
import com.sfy.login.service.LoginService;
import com.sfy.login.util.IpUtil;
import com.sfy.login.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


@RestController
@CrossOrigin
@RequestMapping("/api/user/")
public class UserController {
    @Autowired
    private LoginServiceFactory loginServiceFactory;

    @PostMapping("login.do")
    public R login(String loginType, LoginRequest loginRequest, HttpServletRequest httpServletRequest){
        LoginService loginService = loginServiceFactory.getLoginServiceByType(loginType);
        return loginService.login(loginRequest, IpUtil.getIp(httpServletRequest));
    }
}
